#define DEBUG
#include <cstdio>
#define INF 0x7ffffff
#define MAXN 10000

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static int a[MAXN+1], x[MAXN+1], s[MAXN+1];
  static long long v[MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%lld", v+i);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }

  x[0]=s[0]=0;
  int i, j;
  for (i=1, j=n; i<j; i++, j--) {
    int p=i, q=j;
    long long sumi=v[i], sumj=v[j];
    for (; p<q-1 && sumi!=sumj; ) {
      p++;
      for (; p<q && sumi<sumj; p++) {
	sumi += v[p];
      }
      p--;
      q--;
      for (; p<q && sumi>sumj; q--) {
	sumj += v[q];
      }
      q++;
    }
    if (sumi==sumj && p<q) {
      x[++x[0]] = p-i+1;
      s[++s[0]] = j-q+1;
    } else {
      x[++x[0]] = j-i+1;
    }
    i=p, j=q;
  }

  for (int i=1; i<=s[0]; i++) {
    x[++x[0]]=s[s[0]-i+1];
  }
  n=x[0], s[0]=0;
  for (int i=1; i<=n; i++) {
    s[i] = s[i-1]+x[i];
  }

  static int f[MAXN+1];
  for (int i=1; i<=n/2; i++) {
    f[i]=INF;
    for (int j=0; j<i; j++) {
      f[i] = min(f[i], f[j]+a[s[i]-s[j]]+a[s[n-j]-s[n-i]]);
    }
  }
  if (n%2) {
    f[n/2+1] = f[n/2]+a[s[n/2+1]];
  }
  printf("%d", min(f[n/2+n%2], a[s[n]]));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
